home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9516 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: osip22.ionet.net!user
  2. From: cpruett@ionet.net (Chris Pruett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Pointer arithmetic
  5. Date: Sun, 10 Mar 1996 19:11:45 -0600
  6. Organization: Internet Oklahoma
  7. Message-ID: <cpruett-1003961911450001@osip22.ionet.net>
  8. References: <4h2r55$er@s3.iway.fr>
  9. NNTP-Posting-Host: osip22.ionet.net
  10. X-Newsreader: Yet Another NewsWatcher 2.1.1
  11.  
  12. In article <4h2r55$er@s3.iway.fr>, Pascal Terracol <assetsto@pratique.fr> wrote:
  13.  
  14. >  Hello,
  15. > this sample code have been correctly working on a pc 80286 processor
  16. > I put it on a mac and the pointers seems to act differently...
  17. > any idea about that ? 
  18. >          int size, n1, n2 ;
  19. >          Point  *p_debut, *p1, *p2 ;                                   
  20. /* "vecteur" de translation des adr  */
  21. > ....
  22. >       n1 = (int) (l->p1)/sizeof(Point) ;
  23. >              n2 = (int) (l->p2)/sizeof(Point) ;
  24. >                 
  25. >                   p1 = p_debut + n1 ;
  26. >                     p2 = p_debut + n1 ;
  27. > ....
  28.  
  29. Could it be that the Mac's pointers are 32-bit and the '286 uses 16-bit
  30. pointers?  When you cast the 286 pointer to (int) it works because
  31. the int is itself 16-bits.  On the Mac the 32-bit pointer gets
  32. destroyed.  Perhaps one could change the Mac's compiler setting to use 
  33. 32-bit ints or cast using (long int) instead of (int).
  34.  
  35. The compiler ought to complain with a warning when one tells it to cast a
  36. pointer to an inferior integer type.
  37.  
  38. CP
  39.